import logging
from logging import handlers

class Mylogger(object) :
    def __init__(self,log_path,log_name):
        # 1.指明日志记录到哪个文件 "F:/xxx/xx" + "info.log"
        logfile = log_path + log_name
        # 2.配置日志操作器
        handler = handlers.RotatingFileHandler(logfile, maxBytes=1024 * 1024, backupCount=5, encoding='utf-8')
        # 3.设置日志格式
        fmt = "%(asctime)s %(message)s"
        # 4. 配置格式实例
        formatter = logging.Formatter(fmt,datefmt='%Y-%m-%d,%H:%M:%S')
        # 5.操作器加载格式实例
        handler.setFormatter(formatter)
        # 6.创建logger实例
        self.logger = logging.getLogger()
        # 7.给实例增加日志操作器
        self.logger.addHandler(handler)
        # 8.给实例增加日志输出登记
        self.logger.setLevel(logging.INFO)

    # 设置方法返回looger实例
    def get_logger(self):
        return self.logger